

import { ScrollView, Node, Vec2, Label, VideoPlayer } from 'cc';
import { tween } from 'cc';
import { UIOpacity } from 'cc';
import { view } from 'cc';
import { Vec3 } from 'cc';
import { _decorator, Component } from 'cc';
import { App } from '../../App';
import UtilTool from '../../tools/UtilTool';
import { GameBaseModel } from './GameBaseModel';
const { ccclass, property } = _decorator;

/* 得分变化脚本 */
@ccclass('ChangeScore')
export class ChangeScore extends Component {
    @property(Node)
    content: Node = null;

    @property(Label)
    tipLabel: Label = null;

    @property(Label)
    scoreLabel: Label = null;

    onLoad(): void {
        
    }

    start() {
        
    }

    /**
     * 设置属性
     * @param score 得分
     * @param pos 位置
     * @param tip 提示语
     * @param func 回调
     */
    init(score = 0, pos = new Vec2(0,0), tip = App.language.getLanguageLab(196),func = null) {
        // 提示语
        this.tipLabel.string = tip + ":"

        // 得分
        let scoreStr = score>0?"+"+score:""+score
        if (score>0) {
            scoreStr = "+"+score
        }else if (score==0) {
            scoreStr = App.language.getLanguageLab(196)+score
        } else if (score<0) {
            scoreStr = ""+score
        }
        this.scoreLabel.string = scoreStr

        UtilTool.adaptiveLabel([this.tipLabel.node,this.scoreLabel.node],0,0)

        // 位置
        this.node.setPosition(pos.x, pos.y, 0)

        // 飘动画
        tween()
            .target(this.content)
            .delay(0.5)
            .by(0.8, { position: new Vec3(0, 150, 0) })
            .call(() => {
                this.node.destroy();
                func && func()
            })
            .start()

        tween(this.content.getComponent(UIOpacity))
            .delay(0.7)
            .to(0.6, { opacity: 0 }).start()

    }



}

